#include "linOutputStream.h"
#include <fstream>
#include <cstdlib>

using namespace neiderra::core;

linOutputStream::linOutputStream(Core* core): iOutputStream(core)
{
	using namespace std;
	_output = new std::ofstream();
}

linOutputStream::~ linOutputStream()
{
	close();
	delete _output;
}

bool linOutputStream::open(const char* filename)
{
	using namespace std;
	_filename = filename;
	_output->open(filename, ios::out | ios::trunc);
	return _output->is_open();
}

void linOutputStream::close()
{
	_output->close();
}

int linOutputStream::write(const char* buf, int n)
{
	_output->write(buf, n);
	return n;
}

int linOutputStream::write(const char* buf)
{
	int n = strlen(buf);
	_output->write(buf, n);
	return n;
}

int linOutputStream::writeln(const char* buf)
{
	int n = strlen(buf);
	_output->write(buf, n);
	_output->write("\n",1);
	return n+1;
}

int linOutputStream::writeln(const std::string& s)
{
	return writeln(s.c_str());
}

const char* linOutputStream::sourceName()
{
	return _filename.c_str();
}
